#ifndef _BSP_NAND_W25N_H
#define _BSP_NAND_W25N_H

#include "nand_w25n.h"

#ifdef __cplusplus
extern "C"
{
#endif

	extern nand_info_type bsp_snand_info;

	/*****************************************************************************
	 * @brief   NAND-FLASH COMMON API
	 *****************************************************************************/
	void bsp_snand_reset(void);

	uint8_t bsp_snand_featute_get(uint8_t reg_addr);
	uint8_t bsp_snand_featute_set(uint8_t reg_addr, uint8_t msk, uint8_t dat);

	uint8_t bsp_snand_wait_ready(void);

	uint8_t bsp_snand_ecc_error_get(void);

	uint8_t bsp_snand_write_enable(void);
	uint8_t bsp_snand_write_disable(void);

	void bsp_snand_read_id(uint8_t *dat);

	/* read and write */
	uint8_t bsp_snand_read_page(uint32_t page_addr);

	uint8_t bsp_snand_read_cache(uint16_t coil_addr, uint8_t *dat, uint16_t Len);
	uint8_t bsp_snand_q_read_cache(uint16_t coil_addr, uint8_t *dat, uint16_t Len);

	uint8_t bsp_snand_write_cache(uint16_t coil_addr, const uint8_t *dat, uint16_t Len);   // clear cache and write dat
	uint8_t bsp_snand_random_write_cache(uint16_t addr, const uint8_t *dat, uint16_t Len); // keep cache and write dat
	uint8_t bsp_snand_q_write_cache(uint16_t coil_addr, const uint8_t *dat, uint16_t Len);
	uint8_t bsp_snand_q_random_write_cache(uint16_t addr, const uint8_t *dat, uint16_t Len);

	uint8_t bsp_snand_program_exe(uint32_t page_addr);

	/* erase */
	uint8_t bsp_snand_block_erase(uint32_t block_addr);
	uint8_t bsp_snand_chip_erase(void);
	uint8_t bsp_snand_block_empty_check(uint32_t block_addr); // 需malloc支持

	/* auto cmd */
	void bsp_snand_cmd_exe(uint8_t cmd);
	void bsp_snand_cmd_set(uint8_t cmd, uint8_t par);
	uint8_t bsp_snand_cmd_get(uint8_t cmd);
	void bsp_snand_cmd_auto_set(uint8_t cmd, const uint8_t *buff, uint8_t cnt);
	void bsp_snand_cmd_auto_get(uint8_t cmd, uint8_t *buff, uint8_t cnt);

	/*****************************************************************************
	 * @brief   SPECIAL API for W25N
	 *****************************************************************************/
	uint8_t bsp_w25n_opt_mem_select(void);
	uint8_t bsp_w25n_main_mem_select(void);
	uint8_t bsp_w25n_init(void);

	/*****************************************************************************
	 * @brief   SPECIAL API for GD5
	 *****************************************************************************/
	uint8_t bsp_gd5_opt_mem_select(void);
	uint8_t bsp_gd5_main_mem_select(void);
	uint8_t bsp_gd5_init(void);

#ifdef __cplusplus
}
#endif

#endif
